<?php

namespace AppVue\Http\Controllers;

use AppVue\Models\Record;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
//        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function home()
    {
        return view('home');
    }

    public function index(Request $request) {
        $q = $request->get('q');
        $records = null;
        if (!empty($q)) {
            $search = $q;
            $records = Record::where('parent', 0)
                ->where('name', '=', $search)
                ->orWhere('serial_number', '=', $search)
                ->paginate(15);
        }
        return view('index', compact('records', 'q'));
    }
}
